home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 8206 / 8206.xpi / content / webmail / gmail.js < prev    next >
Text File  |  2010-02-02  |  4KB  |  137 lines

  1. WiseStampLog("[gmail.js] >>>>>");
  2. window.addEventListener("load",function(event){gmailsig.pageload(event)},true);
  3. window.addEventListener("unload",function(event){gmailsig.unload(event)},true);
  4.  
  5. var gmailsig =
  6. {
  7.     gmail: null,
  8.     current: null,
  9.     pageload: function (event)
  10.     {
  11.         WiseStampLog("[gmail.js::pageload] >>>>>");
  12.         wisestampsig.refreshCallback = gmailsig.refreshSignature;
  13.         gmailsig.setupCompose();
  14.         window.addEventListener("DOMNodeInserted", gmailsig.nodeInserted, false);
  15.     },
  16.     unload: function(event)
  17.     {
  18.     },
  19.     handleEvent: function (event)
  20.     {
  21.         WiseStampLog("[gmail.js::handleEvent] >>>>>");
  22.         WiseStampLog("[gmail.js::handleEvent] Event: " + event + "|" + event.type);
  23.     },
  24.     createOptionsIcon: function ()
  25.     {
  26.         var wisestampIcon = document.createElement("span");
  27.         //wisestampIcon.innerHTML="Wisestamp Options";
  28.         wisestampIcon.setAttribute("class", "wisestampIcon");
  29.         wisestampIcon.innerHTML = '<img src="' + wisestampsig.icon + '" width="16" height="16"/>';
  30.         //wisestampIcon.style.marginLeft="10px";
  31.         //wisestampIcon.style.verticalAlign="middle";
  32.         wisestampIcon.setAttribute("style", "margin-left: 10px; margin-bottom: 10px;");
  33.         return wisestampIcon;
  34.     },
  35.     setupCompose: function ()
  36.     {
  37.         WiseStampLog("[gmail.js::setupCompose] >>>>>");
  38.         
  39.         setTimeout(function (a)
  40.         {
  41.             gmailsig.addWisestampIcon();
  42.         },
  43.         500, this);
  44.  
  45.         this.insertSignature();
  46.     },
  47.     iframeTries: 1,
  48.     refreshSignature: function ()
  49.     {
  50.         gmailsig.insertSignature(null, true, "//div[@class='gmail_quote']");
  51.     },
  52.     insertSignature: function (iframe, manual, xPath)
  53.     {
  54.         WiseStampLog("[gmail.js::insertSignature] >>>>>");
  55.         WiseStampLog("[gmail.js::insertSignature] try: " + this.iframeTries);
  56.  
  57.         var retry = !iframe;
  58.         if (!iframe)
  59.         {
  60.             var iframes = document.getElementsByTagName("iframe");
  61.             for (var i = 0; i < iframes.length; i++)
  62.             {
  63.                 if (iframes[i].contentDocument && iframes[i].contentDocument.designMode == "on")
  64.                 {
  65.                     iframe = iframes[i];
  66.                     wisestampsig.insertSignature(iframe, !manual, xPath);
  67.                     retry = false;
  68.                 }
  69.             }
  70.         }
  71.         if (retry && this.iframeTries < 1)
  72.         {
  73.             this.iframeTries++;
  74.             setTimeout(function (a)
  75.             {
  76.                 a.insertSignature(null, manual, xPath);
  77.             },
  78.             0, this);
  79.         }
  80.     },
  81.     nodeInserted: function (event)
  82.     {
  83.         if (event.target && "tagName" in event.target && event.target.tagName == "IFRAME")
  84.         {
  85.             var iframe = event.target;
  86.             
  87.             WiseStampLog("iframe inserted: " + event.target + "\n");
  88.             gmailsig._iframe = iframe;
  89.             
  90.             /* Now listen for when the form closes */
  91.             gmailsig.addWisestampIcon();
  92.             iframe.addEventListener('load', gmailsig.iframeLoad, false);
  93.         }
  94.     },
  95.     iframeLoad: function (event)
  96.     {
  97.         WiseStampLog("[gmail.js::iframeLoad(" + event + "|" + event.target + ")] >>>>>");
  98.  
  99.         setTimeout(function ()
  100.         {
  101.             WiseStampLog("[gmail.js::setTimeout] >>>>>");
  102.             var iframe = gmailsig._iframe;
  103.             if (iframe.contentDocument && iframe.contentDocument.designMode == "on")
  104.                 wisestampsig.insertSignature(iframe, true);
  105.                 
  106.             if (event)
  107.             {
  108.                 try
  109.                 {
  110.                     event.target.removeEventListener('load', gmailsig.iframeLoad, false);
  111.                 } catch(e)
  112.                 {}
  113.             }
  114.         },
  115.         !event ? 500 : 0);
  116.     },
  117.     addWisestampIcon: function ()
  118.     {
  119.         WiseStampLog("[gmail.js::addWisestampIcon] >>>>>");
  120.         if (!wisestampsig.showButton) return;
  121.         //var containers = evaluateXPath(gmailsig.view.ownerDocument,"//td[@class='VByZEe']");
  122.         var containers = evaluateXPath(document, "//span[@class='jNNpPe']");
  123.         WiseStampLog("[gmail.js::addWisestampIcon] Containers length = " + containers.length);
  124.         for (var i = 0; containers && i < containers.length; i++)
  125.         {
  126.             var cont = containers[i];
  127.             var icons = evaluateXPath(cont, "//span[@class='wisestampIcon']");
  128.             if (! (icons && icons.length > 0))
  129.             {
  130.                 WiseStampLog("[gmail.js::addWisestampIcon] adding icon...");
  131.                 var wisestampIcon = gmailsig.createOptionsIcon();
  132.                 cont.appendChild(wisestampIcon);
  133.                 wisestampsig.initOptionsIcon(wisestampIcon);
  134.             }
  135.         }
  136.     }
  137. };